package org.barad.voiceuserinterface.widgets;

public abstract class Widget implements Comparable<Widget> {
	protected static int ID = 0;
	protected int id;
	protected int index;
	protected int height;
	protected int width;
	protected int top;
	protected int left;
	protected int right;
	protected boolean enabled;
	protected float wordsPerMinute;
	
	public Widget() {
		this.id = ID++;
		this.enabled = true;
		this.index = 0;
		this.wordsPerMinute = 170;
	}
	
	/**
	 * Compare two widgets. Used for sorting actiona have less priority
	 * i.e. provided to the user at the end. Otherwise, the priority of
	 * widgets is given from to bottom and from left to right. This is
	 * needed because this interface is serial as opposed to a GUI (for
	 * example).
	 */
	public int compareTo(Widget widget) {
		if (this instanceof Action && !(widget instanceof Action)) {
			return -1;
		} else if(!(this instanceof Action) && widget instanceof Action) {
			return 1;
		} else {
			if (this.top < widget.top) {
				return 1;
			} else if (this.top > widget.top) {
				return -1;
			} else if (this.left < widget.left) {
				return 1;
			} else if (this.left > widget.left) {
				return -1;
			} else {
				return 0;
			}
		}
	}
	
	protected boolean isEmpty(String string) {
		return string == null || string.equals("");
	}
	
	public abstract void interact();
	
	public float getWordsPerMinute() {
		return wordsPerMinute;
	}

	public void setWordsPerMinute(float wordsPerMinute) {
		this.wordsPerMinute = wordsPerMinute;
	}
	
	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getLeft() {
		return left;
	}

	public void setLeft(int left) {
		this.left = left;
	}

	public int getRight() {
		return right;
	}

	public void setRight(int right) {
		this.right = right;
	}

	public int getTop() {
		return top;
	}

	public void setTop(int top) {
		this.top = top;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}
}
